/**
 * @description User Controller
 */

 const {
  queryAll,
  addData,
  updateData,
  deleteData,
  destroyPkgFun
} = require('../service/expense')
const { SuccessModel, ErrorModel } = require('../model/ResModel')
const {
  queryFailInfo,
} = require('../model/ErrorInfo')


/**
 * 查询所有信息
 */
async function queryAllData(params) {
  try {
    const result = await queryAll(params)
    return new SuccessModel(result)
  } catch (ex) {
    return new ErrorModel(queryFailInfo)
  }
}
/**
 * 新增信息
 */
async function addPkg(params) {
  try {
    await addData(params)
    return new SuccessModel(params)
  } catch (ex) {
    return new ErrorModel({})
  }
}
/**
 * 修改信息
 */
async function updatePkg(params, id) {
  try {
    await updateData(params, id)
    return new SuccessModel(params)
  } catch (ex) {
    return new ErrorModel({})
  }
}

/**
 * 删除
 */
 async function deletePkg(id) {
  try {
    await deleteData(id)
    return new SuccessModel({
      msg: '删除成功'
    })
  } catch (ex) {
    return new ErrorModel({})
  }
}

async function destroyPkg() {
  try {
    await destroyPkgFun()
    return new SuccessModel({
      msg: '删除成功'
    })
  } catch (ex) {
    return new ErrorModel({})
  }
}

module.exports = {
  queryAllData,
  addPkg,
  updatePkg,
  deletePkg,
  destroyPkg
}
